<template>
	<view>
		<view class="text-center text-red bg-white">{{form.remek}}</view>

		<view class="">
			<view class="flex text-center text-white text-lg bg">
				<view class="title_btn flex-sub bg" @click="cut(1)" :style="{Color:title_color==1?bgCol2: ''}">个人入驻
				</view>
				<view class="title_btn flex-sub bg" @click="cut(2)" :style="{Color:title_color==2?bgCol2: ''}">企业入驻
				</view>
			</view>

			<view class=" padding" v-if="title_color==1">

				<view class=" padding bg radius">
					<u-form :model="form" ref="uForm" label-position="top" :label-style='lableStyle'>
						<u-form-item label="真实姓名" :border-bottom='false'>
							<u-input placeholder="请输入真实姓名" v-model="form.name" />
						</u-form-item>
						<u-form-item label="证件号码" :border-bottom='false'>
							<u-input placeholder="请输入身份证号码" v-model="form.idNumber" />
						</u-form-item>
					</u-form>
				</view>
				<view class=" padding bg radius margin-top">
					<view class="text-lg">上传身份证正面</view>
					<view class="margin-top"
						style="border: 2rpx dashed #484B74; width: 100%;height: 320rpx;position: relative;">
						<view style="text-align: center;margin: 80rpx auto 0;" @click="addImages(1)" v-if="!form.front">
							<image src="../static/photo.png" mode="widthFix" style="width: 73rpx;"></image>
							<view class="text-sm  margin-top-sm">添加身份证正面</view>
						</view>
						<image @click="disabled? '':addImages(1)" v-else :src="form.front"
							style="width: 100%;height: 320rpx;"></image>
					</view>
				</view>
				<view class="text-white padding bg radius margin-top">
					<view class="text-lg">上传身份证反面</view>
					<view class="margin-top"
						style="border: 2rpx dashed #484B74; width: 100%;height: 320rpx;position: relative;">
						<view style="text-align: center;margin: 80rpx auto 0;" @click="addImages(2)" v-if="!form.back">
							<image src="../static/photo.png" mode="widthFix" style="width: 73rpx;"></image>
							<view class="text-sm margin-top-sm">添加身份证反面</view>
						</view>
						<image @click="disabled? '':addImages(2)" v-else :src="form.back"
							style="width: 100%;height: 320rpx;"></image>
					</view>
				</view>
				<!--  v-if="!disabled" -->
				<!-- <u-button @click="submit" class="margin-top" :custom-style="customStyle" shape="circle"
					:hair-line="false">提交认证</u-button> -->
				<u-button @click="submit" class="margin-top" :custom-style="customStyle" shape="circle"
					:hair-line="false" v-if="geRen!=2">提交认证
				</u-button>
			</view>
			<view class=" padding" v-if="title_color==2">
				<view class=" padding bg radius">
					<u-form :model="forms" ref="uForm" label-position="top" :label-style='lableStyle'>
						<u-form-item label="企业名称" :border-bottom='false'>
							<u-input placeholder="请输入企业名称" v-model="forms.name" />
						</u-form-item>
						<u-form-item label="企业地址" :border-bottom='false'>
							<u-input placeholder="请输入企业地址" v-model="forms.address" />
						</u-form-item>
						<u-form-item label="联系方式" :border-bottom='false'>
							<u-input placeholder="请输入电话号码" v-model="forms.phone" type="number" maxlength="11" />
						</u-form-item>
					</u-form>
				</view>
				<view class=" padding bg radius margin-top">
					<view class="text-lg">营业执照正面</view>
					<view class="margin-top"
						style="border: 2rpx dashed #484B74; width: 100%;height: 320rpx;position: relative;">
						<view style="text-align: center;margin: 80rpx auto 0;" @click="addImages(3)"
							v-if="!forms.front">
							<image src="../static/photo.png" mode="widthFix" style="width: 73rpx;"></image>
							<view class="text-sm  margin-top-sm">添加营业执照正面</view>
						</view>
						<image @click="disabled? '':addImages(3)" v-else :src="forms.front"
							style="width: 100%;height: 320rpx;"></image>
					</view>
				</view>
				<!-- <view class="text-white padding bg radius margin-top">
					<view class="text-lg">上传身份证反面</view>
					<view class="margin-top"
						style="border: 2rpx dashed #484B74; width: 100%;height: 320rpx;position: relative;">
						<view style="text-align: center;margin: 80rpx auto 0;" @click="addImages(2)" v-if="!form.back">
							<image src="../static/photo.png" mode="widthFix" style="width: 73rpx;"></image>
							<view class="text-sm margin-top-sm">添加身份证反面</view>
						</view>
						<image @click="disabled? '':addImages(2)" v-else :src="form.back"
							style="width: 100%;height: 320rpx;"></image>
					</view>
				</view> -->
				<!--  v-if="!disabled" -->
				<u-button @click="submit" class="margin-top" :custom-style="customStyle" shape="circle"
					:hair-line="false" v-if="Qe!=2">提交认证
				</u-button>
			</view>
		</view>

	</view>
</template>

<script>
	import configdata from '../../common/config.js';

	export default {
		data() {
			return {
				title_color: 1,
				classify: 1,
				bgCol2: '#557EFD',
				form: {
					name: '',
					idNumber: '',
					front: '',
					back: '',
					remek: ''
				},
				forms: {
					name: '',
					address: '',
					idNumber: '',
					front: '',
					back: ''
				},
				// disabled: false,
				lableStyle: {
					color: '#000000',
					fontSize: '36upx'
				},
				customStyle: {
					backgroundColor: '#557EFD',
					color: '#000000',
					border: 0
				},
				customStyle1: {
					backgroundColor: '#ccc',
					color: '#000000',
					border: 0
				},
				renzheng: 0,
				Qe: 0,
				geRen: 0
			}
		},
		onLoad(e) {
			console.log(e)
			this.classify = parseInt(e.classify)
			this.title_color = this.classify
			this.getUserInfo()

		},
		onShow() {
			this.Qe = uni.getStorageSync("Qe")
			this.geRen = uni.getStorageSync("geRen")
		},
		methods: {
			cut(e) {
				this.title_color = e
				console.log(this.title_color)
				if (this.title_color == 1) {
					this.classify = 1
				} else if (this.title_color == 2) {
					this.classify = 2
				}
				this.getUserInfo()
			},
			submit() {
				if (this.classify == 1) {
					if (!this.form.name) {
						uni.showToast({
							title: '请输入真实姓名',
							icon: 'none',
							duration: 1000
						})
						return;
					}

					if (!this.form.idNumber) {
						uni.showToast({
							title: '请输入身份证号',
							icon: 'none',
							duration: 1000
						})
						return;
					}
					let regX =
						/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
					if (!regX.test(this.form.idNumber)) {
						uni.showToast({
							title: '请输入正确的身份证号',
							icon: 'none',
							duration: 1000
						})
						return;
					}
					if (!this.form.front) {
						uni.showToast({
							title: '请上传身份证正面',
							icon: 'none',
							duration: 1000
						})
						return;
					}
					if (!this.form.back) {
						uni.showToast({
							title: '请上传身份证反面',
							icon: 'none',
							duration: 1000
						})
						return;
					}
				}
				if (this.classify == 2) {
					if (!this.forms.name) {
						uni.showToast({
							title: '请输入企业姓名',
							icon: 'none',
							duration: 1000
						})
						return;
					}
					if (!this.forms.address) {
						uni.showToast({
							title: '请输入企业地址',
							icon: 'none',
							duration: 1000
						})
						return;
					}
					if (!this.forms.phone) {
						uni.showToast({
							title: '请输入电话号码',
							icon: 'none',
							duration: 1000
						})
						return;
					}

					if (!this.forms.front) {
						uni.showToast({
							title: '请上传营业执照正面',
							icon: 'none',
							duration: 1000
						})
						return;
					}
				}

				let data
				if (this.classify == 1) {

					data = {
						name: this.form.name,
						idNumber: this.form.idNumber,
						front: this.form.front,
						back: this.form.back,
						remek: this.form.remek,
						classify: this.classify
					}
				}

				if (this.classify == 2) {

					data = {
						name: this.forms.name,
						address: this.forms.address,
						phone: this.forms.phone,
						classify: this.classify,
						front: this.forms.front,
						// front: 'https://jiazhengv5.xianmaxiong.com/file/uploadPath/2021/11/08/1915ad52c66abb9537ce50c660236737.jpg'
						// back: this.forms.back,

					}

				}

				this.$Request.post("/app/userCertification/insert", data).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '认证提交成功！',
							icon: 'none'
						})
						setTimeout(function() {
							uni.navigateBack()
						}, 1000)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				});
			},
			getUserInfo() {
				this.$Request.get("/app/userCertification/queryInsert?classify=" + this.classify).then(res => {
					console.log(res)
					if (res.code == 0) {
						uni.setStorageSync('classify', res.data.classify)
						this.classify = res.data.classify
						if (this.classify == 1) {
							this.form.name = res.data.name ? res.data.name : ''
							this.form.idNumber = res.data.idNumber ? res.data.idNumber : ''
							this.form.front = res.data.front ? res.data.front : ''
							this.form.back = res.data.back ? res.data.back : ''
							this.classify = res.data.classify
						} else if (this.classify == 2) {
							this.classify = res.data.classify
							this.forms.name = res.data.name ? res.data.name : ''
							this.forms.address = res.data.address ? res.data.address : ''
							this.forms.phone = res.data.phone ? res.data.phone : ''
							this.forms.front = res.data.front ? res.data.front : ''
						}


						if (res.data.status == 1) {
							this.disabled = true
						}
						if (res.data.status == 2) {
							this.form.remek = res.data.remek ? res.data.remek : ''
						}
					}
				});
			},
			addImages(e) {
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'],
					success: res => {
						for (let i = 0; i < 1; i++) {
							this.$queue.showLoading("上传中...");
							uni.uploadFile({ // 上传接口
								url: this.config("APIHOST1") + '/alioss/upload', //真实的接口地址https://xxpwadmin.xianmxkj.com/sqx_fast/alioss/upload
								// url: 'https://jiazhengv5.xianmaxiong.com/sqx_fast/alioss/upload', 
								filePath: res.tempFilePaths[i],
								name: 'file',
								success: (uploadFileRes) => {
									if (e == 1) {
										this.form.front = JSON.parse(uploadFileRes.data).data
									} else if (e == 3) {
										this.forms.front = JSON.parse(uploadFileRes.data).data
									} else if (e == 2) {
										this.form.back = JSON.parse(uploadFileRes.data).data
									}

									uni.hideLoading();
								}
							});
						}
					}
				})
			},
			config: function(name) {
				var info = null;
				if (name) {
					var name2 = name.split("."); //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null;
					} else {
						info = configdata[name] || null;
					}
					if (info == null) {
						let web_config = cache.get("web_config");
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null;
							} else {
								info = web_config[name] || null;
							}
						}
					}
				}
				return info;
			},
		}
	}
</script>

<style>
	page {
		background-color: #F7F7F7;
	}

	.bg {
		background-color: #FFFFFF;
	}

	.u-size-default {
		background: #557EFD !important;
		color: #FFFFFF !important;
	}

	.u-input__input {
		color: balck !important;
	}

	.title_btn {
		height: 78upx;
		line-height: 78upx;
		/* background: #f7f7f7; */
	}
</style>
